import { Controller, Get, Post, Body, Param, Request, Query } from '@nestjs/common';
import { GoodsService } from './goods.service';
import { CreateGoodDto } from './dto/create-good.dto';

@Controller('goods')
export class GoodsController {
  constructor(private readonly goodsService: GoodsService) {}

  @Post('save')
  async create(@Body() createGoodDto: CreateGoodDto, @Request() req: any) {
    const result = await this.goodsService.create(createGoodDto, req.tokenInfo );
    return { 
      message: result ? '操作成功': '失败'
    }
  }

  @Get('load')
  async findAll(@Query() query: any) {
    const [data, total] = await this.goodsService.findAll(query);
    return {
      data,
      total
    }
  }
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.goodsService.findOne(+id);
  }

  @Get('delete/:id')
  async delete(@Param('id') id: string) {
    const result = await this.goodsService.delete(id);
    return { 
      message: result ? '完全删除成功': '失败'
    }
  }
  @Get('remove/:id')
  async remove(@Param('id') id: string) {
    const result = await this.goodsService.remove(id);
    return { 
      message: result ? '删除成功': '失败'
    }
  }
}
